<html>
<head><meta charset="utf-8"><title>derive guards · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html">derive guards</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="213467856"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213467856" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213467856">(Oct 15 2020 at 18:28)</a>:</h4>
<p>I have to admit, <span class="user-mention" data-user-id="127859">@Taylor Cramer</span>, that the more I think about your <code>impl</code> syntax idea, the more I kind of like it</p>



<a name="213467936"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213467936" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213467936">(Oct 15 2020 at 18:28)</a>:</h4>
<p>And this does feel like an "pretty frequent irritant" for me</p>



<a name="213468039"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213468039" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213468039">(Oct 15 2020 at 18:29)</a>:</h4>
<p>not sure how representative my own experience is :) but I'm guessing others encounter it too</p>



<a name="213470141"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213470141" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213470141">(Oct 15 2020 at 18:45)</a>:</h4>
<p>I am personally a big fan of <code>#[derive] impl Foo for Bar {}</code> and that can modify the impl and gets passed the tokens for Bar. It might not be feasible to implement though.</p>



<a name="213470233"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213470233" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213470233">(Oct 15 2020 at 18:46)</a>:</h4>
<p>I am not feeling enthusiastic about the impl headers inside the derive() parens, feels sort of ugly. I guess maybe it won't be too common?</p>



<a name="213470273"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213470273" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213470273">(Oct 15 2020 at 18:46)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> I don't have the context here; what was the <code>impl</code> syntax idea?</p>



<a name="213470329"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213470329" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213470329">(Oct 15 2020 at 18:47)</a>:</h4>
<p><code>#[derive(impl&lt;T&gt; Clone)] struct Bar&lt;T&gt; { .. }</code></p>



<a name="213470362"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213470362" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213470362">(Oct 15 2020 at 18:47)</a>:</h4>
<p>avoiding the <code>T: Clone</code> bound that would normally get inserted</p>



<a name="213470381"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213470381" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213470381">(Oct 15 2020 at 18:47)</a>:</h4>
<p>(potentially w/o the impl piece of that, syntax is of course bikeshed friendly)</p>



<a name="213470425"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213470425" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213470425">(Oct 15 2020 at 18:47)</a>:</h4>
<p>Ah, I see.</p>



<a name="213470492"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213470492" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213470492">(Oct 15 2020 at 18:48)</a>:</h4>
<p><a href="https://paper.dropbox.com/doc/Backlog-bonanza--A9gb1xQC11ttShtM8qeWdV9fAg-2IcACiM0KX1up1thIeiWh">https://paper.dropbox.com/doc/Backlog-bonanza--A9gb1xQC11ttShtM8qeWdV9fAg-2IcACiM0KX1up1thIeiWh</a></p>



<a name="213470558"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213470558" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213470558">(Oct 15 2020 at 18:48)</a>:</h4>
<p>there was some discussion as part of bonanza yesterday; <span class="user-mention" data-user-id="127859">@Taylor Cramer</span> I believe was proposing perhaps merging that RFC or at least letting experimentation proceed. I think we didn't end up with a consensus point though</p>



<a name="213472480"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213472480" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213472480">(Oct 15 2020 at 19:01)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> I don't know, the <code>#[derive]</code> sugar feels like a "lot more typing" --</p>



<a name="213472501"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213472501" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213472501">(Oct 15 2020 at 19:01)</a>:</h4>
<p>otoh packing a ton of info into that <code>#[derive]</code> might be a lot</p>



<a name="213472522"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213472522" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213472522">(Oct 15 2020 at 19:01)</a>:</h4>
<p>right, yes, that's my worry</p>



<a name="213472527"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213472527" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213472527">(Oct 15 2020 at 19:02)</a>:</h4>
<p>sometimes when there are a lot of <code>#[.]</code> attributes I feel kind of overwhelmed</p>



<a name="213472583"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213472583" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213472583">(Oct 15 2020 at 19:02)</a>:</h4>
<p>I guess I stand by my conclusion from backlog bonanza anyway</p>



<a name="213472606"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213472606" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213472606">(Oct 15 2020 at 19:02)</a>:</h4>
<p>that "I'd like to see this problem pursued but it takes somebody dedicated"</p>



<a name="213472667"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213472667" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213472667">(Oct 15 2020 at 19:02)</a>:</h4>
<p>The idea of <code>#[derive] impl X for Y</code> blocks seems interesting; it has the advantage of not hanging an ever-increasing number of things off the struct definition.</p>



<a name="213472698"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213472698" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213472698">(Oct 15 2020 at 19:02)</a>:</h4>
<p>I think that if there's a derive that's not doing "the totally normal thing" it's fair to write a little more than a little less</p>



<a name="213472708"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213472708" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213472708">(Oct 15 2020 at 19:02)</a>:</h4>
<p>yes. it just requires a non-trivial extension to procedural macros</p>



<a name="213472709"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213472709" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213472709">(Oct 15 2020 at 19:02)</a>:</h4>
<p>I'm a fan of the idea of declarations that don't have to be read "from the middle".</p>



<a name="213472784"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213472784" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213472784">(Oct 15 2020 at 19:03)</a>:</h4>
<p>When you write <code>#[derive(...)] #[repr(...)] #[etc] struct Foo { ... </code>, that's a lot of preface before you know what struct you're talking about.</p>



<a name="213472818"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213472818" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213472818">(Oct 15 2020 at 19:03)</a>:</h4>
<p>We've talked before about "standalone" deriving declarations.</p>



<a name="213474056"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213474056" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213474056">(Oct 15 2020 at 19:13)</a>:</h4>
<p>I'm interested in that approach but (a) it feels like a significant verbosity cliff compared with <code>derive(Clone)</code> and (b) I don't really have a good feel for if/how we can implement the procedural macro expansion required. Probably that's another good signal that this needs a project group to plan out, preferably one which includes someone familiar with the implementation details of the procedural macro engine.</p>



<a name="213474174"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213474174" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213474174">(Oct 15 2020 at 19:14)</a>:</h4>
<p>to (a), <code>derive(Clone)</code> literally can't produce the correct result in these cases.</p>



<a name="213474316"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213474316" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213474316">(Oct 15 2020 at 19:15)</a>:</h4>
<p><span class="user-mention" data-user-id="224471">@Lokathor</span> sorry, to clarify I'm referring to there being a large "cliff" in ergonomics if the alternative to <code>derive(Clone)</code> is <code>#[derive] impl&lt;....&gt; Clone for ... { ... }</code>, as compared with <code>derive(impl&lt;...&gt; Clone)</code> which is comparatively closer to the original</p>



<a name="213476795"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213476795" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213476795">(Oct 15 2020 at 19:35)</a>:</h4>
<p>I wonder if it'd be an ergonomic improvement to allow something like:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">Foo</span><span class="w"></span>
<span class="k">where</span><span class="w"></span>
<span class="w">    </span><span class="n">derive</span><span class="p">(</span><span class="nb">Clone</span><span class="w"> </span><span class="o">..</span><span class="p">.)</span><span class="w"></span>
<span class="p">{</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="213476849"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213476849" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213476849">(Oct 15 2020 at 19:35)</a>:</h4>
<p>So that the <code>struct Foo</code> can come <em>first</em> and give the sentence a noun. ;)</p>



<a name="213476983"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213476983" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213476983">(Oct 15 2020 at 19:36)</a>:</h4>
<p>(Endlessly bikesheddable, of course.)</p>



<a name="213496101"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213496101" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213496101">(Oct 15 2020 at 22:30)</a>:</h4>
<p>I'd love to have a way to do a bunch of this in "real" syntax rather than attributes and making people write proc macros.</p>
<p>I have no idea how it should actually work, but can see a blurry variadic-generic map reduce kind of thing...</p>



<a name="213496493"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213496493" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213496493">(Oct 15 2020 at 22:36)</a>:</h4>
<p>Looking closer to practicality, I wonder if a survey of where the default bounds are inappropriate could find a narrower change.</p>
<p>To me, what I tend to think of is things like where I'm holding <code>Arc&lt;T&gt;</code> so don't need <code>T: Clone</code> for <code>Self: Clone</code>, or holding a <code>Vec&lt;T&gt;</code> so don't need <code>T: Default</code> for <code>Self: Default</code>.  Is that kind of thing the usual or rare?  If it's particularly common, is there a simpler change that could happen to improve it, without giving up the semver stability that's why we didn't look at the field types to begin with?</p>



<a name="213559281"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213559281" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213559281">(Oct 16 2020 at 13:25)</a>:</h4>
<p>(deleted)</p>



<a name="213559343"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213559343" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213559343">(Oct 16 2020 at 13:26)</a>:</h4>
<p>For what is worth, although it would not cover all the use-cases, having a smarter expansion of <code>#[derive()]</code>s would be another neat thing to do</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#[derive(Clone, Copy)]</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">Ptr</span><span class="o">&lt;</span><span class="n">T</span><span class="w"> </span>: <span class="o">?</span><span class="nb">Sized</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">inner</span>: <span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="n">T</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span><span class="w"> </span>: <span class="o">?</span><span class="nb">Sized</span><span class="o">&gt;</span><span class="w"> </span><span class="nb">Clone</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">Ptr</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"></span>
<span class="k">where</span><span class="w"></span>
<span class="w">    </span><span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="n">T</span><span class="w"> </span>: <span class="nb">Clone</span><span class="p">,</span><span class="w"></span>
<span class="p">{</span><span class="w"> </span><span class="o">..</span><span class="p">.</span><span class="w"> </span><span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span><span class="w"> </span>: <span class="o">?</span><span class="nb">Sized</span><span class="o">&gt;</span><span class="w"> </span><span class="nb">Copy</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">Ptr</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"></span>
<span class="k">where</span><span class="w"></span>
<span class="w">    </span><span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="n">T</span><span class="w"> </span>: <span class="nb">Copy</span><span class="p">,</span><span class="w"></span>
<span class="p">{}</span><span class="w"></span>
</code></pre></div>

<p>Of course, that'd require <code>trivial_bounds</code> to be usable, but imho that's just the more reason to enable <code>trivial_bounds</code> <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>
<hr>
<p>Also, that's currently the only way to get <code>structural_eq</code> for such cases:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#[derive(PartialEq, Eq, Clone, Copy)]</span><span class="w"></span>
<span class="k">pub</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">__Ptr</span><span class="o">&lt;</span><span class="n">Inner</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">inner</span>: <span class="nc">Inner</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">pub</span><span class="w"> </span><span class="k">type</span> <span class="nc">Ptr</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">__Ptr</span><span class="o">&lt;*</span><span class="k">const</span><span class="w"> </span><span class="n">T</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>
</code></pre></div>

<p>(cc <span class="user-mention" data-user-id="224471">@Lokathor</span>'s aside in <a href="https://rust-tutorials.github.io/learn-gba/volatile.html#abstracting-volatile">https://rust-tutorials.github.io/learn-gba/volatile.html#abstracting-volatile</a>)</p>



<a name="213590215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213590215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Quy Nguyen <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213590215">(Oct 16 2020 at 17:31)</a>:</h4>
<p>Doesn't that break encapsulation though? You would need to know private types in order to determine if something is cloneable (even from a user perspective). I think my favorite solution would be a smarter proc macro that you can put on an impl block or had access to some type info, if that's even possible.</p>



<a name="213593145"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213593145" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213593145">(Oct 16 2020 at 17:55)</a>:</h4>
<p><span class="user-mention" data-user-id="232018">@Daniel Henry-Mantilla</span> That comes up periodically -- such as <a href="https://users.rust-lang.org/t/cannot-call-default-default-on-map-of-non-default-value-type/50050/6?u=scottmcm">https://users.rust-lang.org/t/cannot-call-default-default-on-map-of-non-default-value-type/50050/6?u=scottmcm</a> a few days ago.  It's hard to weigh the semver consequences.</p>



<a name="213612181"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213612181" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213612181">(Oct 16 2020 at 20:47)</a>:</h4>
<p><span class="user-mention silent" data-user-id="127859">Taylor Cramer</span> <a href="#narrow/stream/213817-t-lang/topic/derive.20guards/near/213474056">said</a>:</p>
<blockquote>
<p>Probably that's another good signal that this needs a project group to plan out, preferably one which includes someone familiar with the implementation details of the procedural macro engine.</p>
</blockquote>
<p>Yeah I guess that's right. I also agree with you though, <span class="user-mention" data-user-id="127859">@Taylor Cramer</span>, that I feel like if the "step up" from <code>#[derive(Clone)]</code> is that I have to go make an impl, I'll be annoyed.</p>



<a name="213612208"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213612208" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213612208">(Oct 16 2020 at 20:47)</a>:</h4>
<p><code>#[derive(impl&lt;T&gt; Clone)]</code> would annoy me less</p>



<a name="213622024"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213622024" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213622024">(Oct 16 2020 at 22:45)</a>:</h4>
<p>I still like <code>#[derive&lt;T&gt;(Clone)]</code>, which also extend well to multiple traits at once</p>



<a name="213622157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213622157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213622157">(Oct 16 2020 at 22:47)</a>:</h4>
<p>Although I think when I mentioned that before, the idea was to list the parameters that <em>should</em> have matching <code>T: Trait</code> constraints, so <code>#[derive&lt;&gt;(Clone)]</code> would be the way to have no constraints</p>



<a name="213622278"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213622278" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213622278">(Oct 16 2020 at 22:49)</a>:</h4>
<p><code>#[derive&lt;_&gt;(Clone)]</code> maybe?</p>



<a name="213625087"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213625087" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213625087">(Oct 16 2020 at 23:46)</a>:</h4>
<p>Sortof-related: where are we standing on implied bounds work these days?  This seems like another of the things that currently encourages putting bounds on impls instead of types.  (It's not clear to me that we actually want to change that convention, but it came to mind.)</p>



<a name="213631501"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213631501" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213631501">(Oct 17 2020 at 02:34)</a>:</h4>
<p><span class="user-mention" data-user-id="125270">@scottmcm</span> I think the only implementation is still the one in chalk</p>



<a name="213631580"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213631580" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213631580">(Oct 17 2020 at 02:37)</a>:</h4>
<p>Ah, thanks.  Postponed waiting on the new implementation sounds reasonable.</p>



<a name="213638180"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213638180" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213638180">(Oct 17 2020 at 06:31)</a>:</h4>
<p>Idea: <code>with</code> clause to put things that normally preface an item after it. e.g.</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">Foo</span><span class="w"> </span><span class="n">with</span><span class="w"> </span><span class="k">pub</span><span class="p">(</span><span class="k">crate</span><span class="p">),</span><span class="w"> </span><span class="n">derive</span><span class="p">(</span><span class="nb">Clone</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">..</span><span class="p">.</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="213664077"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213664077" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213664077">(Oct 17 2020 at 18:21)</a>:</h4>
<p>Just throwing this out: Haskell has a <code>deriving</code> clause roughly like this:</p>
<div class="codehilite" data-code-language="Haskell"><pre><span></span><code><span class="kr">data</span> <span class="kt">Foo</span> <span class="ow">=</span> <span class="kt">Foo</span> <span class="kt">Int</span>
    <span class="kr">deriving</span> <span class="p">(</span><span class="kt">Eq</span><span class="p">,</span> <span class="kt">Ord</span><span class="p">)</span>
</code></pre></div>



<a name="213664156"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213664156" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213664156">(Oct 17 2020 at 18:22)</a>:</h4>
<p>So we <em>could</em> have:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">val</span>: <span class="kt">i32</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"> </span><span class="n">derive</span><span class="p">(</span><span class="nb">Clone</span><span class="p">)</span><span class="w"></span>
</code></pre></div>

<p>Although I actually prefer the current derive syntax <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>



<a name="213839587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/derive%20guards/near/213839587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/derive.20guards.html#213839587">(Oct 19 2020 at 20:19)</a>:</h4>
<p><span class="user-mention silent" data-user-id="138448">cuviper</span> <a href="#narrow/stream/213817-t-lang/topic/derive.20guards/near/213622024">said</a>:</p>
<blockquote>
<p>I still like <code>#[derive&lt;T&gt;(Clone)]</code>, which also extend well to multiple traits at once</p>
</blockquote>
<p>interesting</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>